home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / fractal / kaos.lha / complib / dtmatrix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-26  |  1010 b   |  51 lines

  1. /*
  2. ### 3-dim array memory allocation ###
  3. */
  4.  
  5. double ***dtmatrix(nvl,nvh,nrl,nrh,ncl,nch)
  6. int nvl,nvh,nrl,nrh,ncl,nch;
  7. {
  8.     int i,j,k;
  9.     double ***m;
  10.     void free_vtmatrix();
  11.  
  12.     m = (double ***) malloc((unsigned) (nvh - nvl + 1) * sizeof(double **));
  13.     if(!m) {
  14.         system_mess_proc(1,"dtmatrix: memory allocation failure.");
  15.         return(0);
  16.     }
  17.     else {
  18.         m -= nvl;
  19.     }
  20.     
  21.     for(i=nvl;i<=nvh;i++){
  22.  
  23.         m[i] = (double **) malloc((unsigned) (nrh - nrl + 1) * sizeof(double *));
  24.         if(!m[i]) {
  25.             system_mess_proc(1,"dtmatrix: memory allocation failure.");
  26.             free_dtmatrix(m,nvl,i-1,nrl,nrh,ncl,nch);
  27.             return(0);
  28.         }
  29.         else {
  30.             m[i] -= nrl;
  31.         }
  32.     
  33.         for(j=nrl;j<=nrh;j++){
  34.             m[i][j] = (double *) malloc((unsigned) (nch - ncl + 1) * sizeof(double));
  35.             if(!m[i][j]) {
  36.                 system_mess_proc(1,"dtmatrix: memory allocation failure.");
  37.                 for(k=nrl;k<j;k++) {
  38.                     free(m[i][k]+ncl);
  39.                 }
  40.                 free(m[i]+nrl);
  41.                 free_dtmatrix(m,nvl,i-1,nrl,nrh,ncl,nch);
  42.                 return(0);
  43.             }
  44.             else {
  45.                 m[i][j] -= ncl;
  46.             }
  47.         }
  48.     }
  49.     return(m);
  50. }
  51.